package com.chen.manager.controller;

import com.chen.manager.service.SysUserService;
import com.chen.model.dto.system.SysUserDto;
import com.chen.model.entity.system.SysUser;
import com.chen.model.vo.common.Result;
import com.chen.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author cgj
 * @date 2/14/25 9:01 AM
 */
@RestController
@RequestMapping("/admin/system/sysUser")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;
    @GetMapping("/getSysUserByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<SysUser>> getSysUserByPage(@PathVariable Integer pageNum,
                                                      @PathVariable Integer pageSize,
                                                      SysUserDto sysUserDto){
        PageInfo<SysUser> pageInfo=sysUserService.selectSysUserByPage(pageNum,pageSize,sysUserDto);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }
    /**
     * /admin/system/sysUser/save
     */
    @PostMapping("/sava")
    public Result sava(@RequestBody SysUser sysUser){
        sysUserService.savaUser(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 修改用户
     */
    @PutMapping("/edit")
    public Result edit(@RequestBody SysUser sysUser){
        sysUserService.editUser(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    /**
     * 删除用户 deleteUserById/${id}
     */
    @DeleteMapping("/deleteUserById/{id}")
    public  Result deleteUserById (@PathVariable Integer id){
        sysUserService.deleteUserById(id);
        return  Result.build(null,ResultCodeEnum.SUCCESS);
    }
}
